WTL Controls
|
Back to the WTL Controls Home Page. |
A CComboBox descendant providing customizable background and text colors for both the edit and list box portions of the control. More...
#include <ComboBoxPlus.h>
Public Member Functions | |
CComboBoxPlus () noexcept | |
virtual | ~CComboBoxPlus () |
void | SubclassComboBox (HWND hWnd) |
Subclass a combobox control and create GDI brushes. More... | |
void | UnSubclassComboBox () |
Un-subclass main and component windows; free GDI resources. More... | |
void | SetControlBackColor (COLORREF value) |
Sets a new background color for the control portion of the combobx when it doesn't have focus. More... | |
COLORREF | GetControlBackColor () const |
Default: COLOR_WINDOW . More... | |
void | SetControlTextColor (COLORREF value) |
Set a new text color for the control portion of the combobox when it doesn't have focus. More... | |
COLORREF | GetControlTextColor () const |
Default: COLOR_WINDOWTEXT . More... | |
void | SetControlFocusedBackColor (COLORREF value) |
Set a new background color for the control portion of the combobox when it has focus. More... | |
COLORREF | GetControlFocusedBackColor () const |
Default: COLOR_WINDOW . More... | |
void | SetControlFocusedTextColor (COLORREF value) |
Set a new text color for the control portion of the combobox when it has focus. More... | |
COLORREF | GetControlFocusedTextColor () const |
Default: CLR_RED . More... | |
void | SetListBoxBackColor (COLORREF value) |
Set a new background color for the listbox portion of the combobox. More... | |
COLORREF | GetListBoxBackColor () const |
Default: COLOR_WINDOW . More... | |
void | SetListBoxTextColor (COLORREF value) |
Set a new text color for the listbox portion of the combobox. More... | |
COLORREF | GetListBoxTextColor () const |
Default: COLOR_WINDOWTEXT . More... | |
void | SetAutoAdjustDropRectWidth (bool value) |
Change the AutoAdjustRectWidth state. More... | |
bool | GetAutoAdjustDropRectWidth () const |
Default: true . More... | |
void | SetMaxDropDownWidth (int value) |
Sets the upper limit to the width of the dropdown list, if it is being automatically adjusted. More... | |
int | GetMaxDropDownWidth () const |
Default: 400 pixels. More... | |
void | SetReadOnly (bool read_only=true) |
Change the read-only state of the combobox. More... | |
bool | GetReadOnly () const |
Default: false . More... | |
void | UpdateDropDownWidth () |
Force an update of the width of the drop down list. More... | |
A CComboBox descendant providing customizable background and text colors for both the edit and list box portions of the control.
This class handles WM_CTLCOLOR variants to provide custom background and text colors for the edit and listbox portions of a combo box. It even allows for different colors for focused vs. non-focused states.
This class also provides automatic adjustment of the width of the dropdown portion of the combobox. A MaxDropDownWidth property limits the maximum width, while the minimum width is limited to the width of the static or edit control component. Within these limits, the drop down width will adjust itself to accomodate the longest string in the list.
The parent dialog must reflect WM_CTLCOLOREDIT messages to the control. Use either the non-discriminating REFLECT_NOTIFICATIONS_EX, or with something more selective (e.g, REFLECT_NOTIFICATIONS_MSG_FILTERED).
NOTE: In Windows 10, the custom coloring of the control portion of a combobox only works with 'simple' (created with the CBS_SIMPLE style flag) comboboxes or 'drop down' (created with the CBS_DROPDOWN) comboboxes. Custom coloring of drop-list comboboxes (those created with the CBS_DROPLIST style flag) via WM_CTLCOLOR messages is limited to the listbox portion of the control. In the past, drop-list boxes sent WM_CTLCOLORSTATIC messages; in effect, in read-only comboboxes, the edit control was replaced with a static control, and it was possible to manipulate it with WM_CTLCOLORSTATIC. In Windows 10, that is no longer the case. It appears that drop list boxes no longer send WM_CTLCOLORSTATIC messages; instead, they send WM_CTLCOLOREDIT messages like edit-able comboboxes do, but any modifications made to the control's appearance in response to WM_CTLCOLOREDIT are ignored.
If you need a drop-list combobox with fully customizable colors, use a CODComboxBox (the owner-drawn alternative to CComboBoxPlus).
HOWEVER! All that being said, there is a way to approximate the behavior of a fully owner-drawn, drop-list combobox while still employing the WM_CTLCOLOR technique of customizing the appearance - simply make the edit portion of a drop down combobox read-only. Aside from some minor differences (e.g., a context menu that doesn't exist in true drop-list comboboxes), it looks and works like a fully customized, owner-drawn drop-list combob box.
Typical usage is depicted below.
Definition at line 70 of file ComboBoxPlus.h.
|
noexcept |
Definition at line 21 of file ComboBoxPlus.cpp.
|
virtual |
Definition at line 46 of file ComboBoxPlus.cpp.
void BIS_WTL_CONTROLS::CComboBoxPlus::SubclassComboBox | ( | HWND | hWnd | ) |
Subclass a combobox control and create GDI brushes.
This also grabs the window handles of the list box and control portions of the combobox. Note that the control portion can be either a static text control or a edit control, depending on whether or not the contents of the combobox can be edited.
hWnd | The window handle of the control to subclass. |
void |
Definition at line 67 of file ComboBoxPlus.cpp.
void BIS_WTL_CONTROLS::CComboBoxPlus::UnSubclassComboBox | ( | ) |
Un-subclass main and component windows; free GDI resources.
Definition at line 96 of file ComboBoxPlus.cpp.
void BIS_WTL_CONTROLS::CComboBoxPlus::SetControlBackColor | ( | COLORREF | value | ) |
Sets a new background color for the control portion of the combobx when it doesn't have focus.
value | New control background color. |
void |
Definition at line 257 of file ComboBoxPlus.cpp.
COLORREF BIS_WTL_CONTROLS::CComboBoxPlus::GetControlBackColor | ( | ) | const |
Default: COLOR_WINDOW
.
Returns the background color of the control portion of the combobox when it doesn't have focus.
COLORREF | Current non-focused control background color. |
Definition at line 243 of file ComboBoxPlus.cpp.
void BIS_WTL_CONTROLS::CComboBoxPlus::SetControlTextColor | ( | COLORREF | value | ) |
Set a new text color for the control portion of the combobox when it doesn't have focus.
value | New control text color. |
void |
Definition at line 289 of file ComboBoxPlus.cpp.
COLORREF BIS_WTL_CONTROLS::CComboBoxPlus::GetControlTextColor | ( | ) | const |
Default: COLOR_WINDOWTEXT
.
Returns the text color used in the control portion of the combobox when it doesn't have focus.
COLORREF | Current non-focused control text color. |
Definition at line 275 of file ComboBoxPlus.cpp.
void BIS_WTL_CONTROLS::CComboBoxPlus::SetControlFocusedBackColor | ( | COLORREF | value | ) |
Set a new background color for the control portion of the combobox when it has focus.
value | New focused control background color. |
void |
Definition at line 317 of file ComboBoxPlus.cpp.
COLORREF BIS_WTL_CONTROLS::CComboBoxPlus::GetControlFocusedBackColor | ( | ) | const |
Default: COLOR_WINDOW
.
Returns the background color of the control portion of the combobox when it has focus.
COLORREF | Current focused control background color. |
Definition at line 303 of file ComboBoxPlus.cpp.
void BIS_WTL_CONTROLS::CComboBoxPlus::SetControlFocusedTextColor | ( | COLORREF | value | ) |
Set a new text color for the control portion of the combobox when it has focus.
value | New focused control text color. |
void |
Definition at line 350 of file ComboBoxPlus.cpp.
COLORREF BIS_WTL_CONTROLS::CComboBoxPlus::GetControlFocusedTextColor | ( | ) | const |
Default: CLR_RED
.
Returns the text color for the control portion when it has focus.
COLORREF | Current focused control text color. |
Definition at line 335 of file ComboBoxPlus.cpp.
void BIS_WTL_CONTROLS::CComboBoxPlus::SetListBoxBackColor | ( | COLORREF | value | ) |
Set a new background color for the listbox portion of the combobox.
value | The new background color for the listbox portion of the combobox. |
void |
Definition at line 378 of file ComboBoxPlus.cpp.
COLORREF BIS_WTL_CONTROLS::CComboBoxPlus::GetListBoxBackColor | ( | ) | const |
Default: COLOR_WINDOW
.
Returns the color used for the background of the listbox portion of the combobox.
COLORREF | Current listbox background color. |
Definition at line 364 of file ComboBoxPlus.cpp.
void BIS_WTL_CONTROLS::CComboBoxPlus::SetListBoxTextColor | ( | COLORREF | value | ) |
Set a new text color for the listbox portion of the combobox.
value | New listbox text color. |
void |
Definition at line 410 of file ComboBoxPlus.cpp.
COLORREF BIS_WTL_CONTROLS::CComboBoxPlus::GetListBoxTextColor | ( | ) | const |
Default: COLOR_WINDOWTEXT
.
Returns the color used for text in the listbox portion of the combobox.
COLORREF | Current listbox text color. |
Definition at line 396 of file ComboBoxPlus.cpp.
void BIS_WTL_CONTROLS::CComboBoxPlus::SetAutoAdjustDropRectWidth | ( | bool | value | ) |
Change the AutoAdjustRectWidth state.
value | New bool state. |
void |
Definition at line 199 of file ComboBoxPlus.cpp.
bool BIS_WTL_CONTROLS::CComboBoxPlus::GetAutoAdjustDropRectWidth | ( | ) | const |
Default: true
.
If true
, the drop box width is adjusted to accommodate the longest string. The width will not be less than the control width, and will not be greater than the max limit set through SetMaxDropDownWidth. if false
, drop down width will be equal to the control width.
bool |
Definition at line 184 of file ComboBoxPlus.cpp.
void BIS_WTL_CONTROLS::CComboBoxPlus::SetMaxDropDownWidth | ( | int | value | ) |
Sets the upper limit to the width of the dropdown list, if it is being automatically adjusted.
value | New maximum, in pixels. |
void |
Definition at line 228 of file ComboBoxPlus.cpp.
int BIS_WTL_CONTROLS::CComboBoxPlus::GetMaxDropDownWidth | ( | ) | const |
Default: 400 pixels.
The maximum width allowed when AutoAdjustDropRectWidth is true
.
int |
Definition at line 214 of file ComboBoxPlus.cpp.
void BIS_WTL_CONTROLS::CComboBoxPlus::SetReadOnly | ( | bool | value = true | ) |
Change the read-only state of the combobox.
If set true, and if the combobox is of the 'simple' or 'drop down' type, the edit portion of the combobox will be made read-only, approximating the appearance and behavior of a fully owner-drawn drop list combobox.
value | The new read-only state. |
void |
Definition at line 440 of file ComboBoxPlus.cpp.
bool BIS_WTL_CONTROLS::CComboBoxPlus::GetReadOnly | ( | ) | const |
Default: false
.
Returns the current ReadOnly bool state.
bool |
Definition at line 423 of file ComboBoxPlus.cpp.
void BIS_WTL_CONTROLS::CComboBoxPlus::UpdateDropDownWidth | ( | ) |
Force an update of the width of the drop down list.
If AutoAdjustWidth is true, the drop-down width will be set equal to the length of the longest string in the list box, within limits: if the length of the longest string is less than the width of the control portion of the combobox, the width will be set to the width of the control portion, and if the width of the longest string is greater than the MaxDropDownWidth value, the width will be set to MaxDropDownWidth.
If AutoAdjustWidth is /c false, the width of the dropdown list will be set equal to the width of the control portion of the combobox.
void |
Definition at line 124 of file ComboBoxPlus.cpp.